<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>归还</title>
  <link rel="stylesheet" href="css/base.css">
  <link rel="stylesheet" href="css/back.css">
  <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1, user-scalable=no">
</head>
<body>
<div class="header-box">
  <p>归还</p>
</div>
<div class="back_title">
  <div class="back_title_box">
    <table></table>
    <p class="backAddress_title">确认要归还以下绘本</p>
  </div>
</div>
  <div class="backAddress_box">
    <ul id="back_list" class="backAddress_list">
    </ul>
  </div>

<div class="back_title">
  <div class="back_title_box">
    <table></table>
    <p class="backAddress_title">请选择您的还书地点</p>
  </div>
</div>
<div class="backAddress">
  <div class="backAddress_box">
    <ul id="backAddress_list" class="backAddress_list">
    </ul>
  </div>
  <div class="chose_backAddress">
    <a href="javascript:;" id="aa11">取消</a>
    <a href="#" id="submit" class="a_back">确定</a>
  </div>
</div>
</body>
<script id="bookAddress_show_tmpl" type="text/x-jsrender">
<li id="{{:id}}">
<i></i>
<p>{{:placeShortName}}</p>
</li>
</script>

<script src="js/jquery.js"></script><script src="js/jquery.cookie.js"></script>
<script src="js/base.js?v=base.js?v=20180102"></script>
<script src="js/jsrender.js"></script>
<script>
$(document).on("click",'#backAddress_list li',function() {
	$(this).siblings().children('i').removeClass('back_act');
	$(this).find("i").attr('class', 'back_act');
	
});

getBorrowPlace(); 

  $("#aa11").click(function(){
    history.go(-1);
  })
  $("#submit").click(function(){
	  returnBook();
  })
  
  var ids = getQueryString("ids");
  var names = getQueryString("names");
  if(ids == null || ids == ""){
	  alert("请先选择要归还的绘本！");
	  history.go(-1);
  }
  
  var namess = decodeURI(names).split(",");
  $("#back_list").html("");
  $.each(namess,function(key, value){
	  $("#back_list").append("<li><i class='back_act'></i><p>"+value+"</p></li>");
  });
  
  
function getBorrowPlace(){
	 //获取所有借阅点
	$.get({
		url : window.baseUrl + "/api/book/borrowPlace/findPage",
		data : {
			"pageNum" : 1,
			"pageSize" : 50
		},
		success : function(data) {
			var data = data.data.list;
			$("#backAddress_list").empty();
			var htmlOutput = $.templates("#bookAddress_show_tmpl").render(data);
			$("#backAddress_list").html(htmlOutput);
		}
	});
}

// 归还图书
function returnBook(){
	// 获取借阅点
	var bid = $(".back_act").parents("li").attr("id");
	if(bid==null || bid==""){
		alert("请选择借阅点！");
		return;
	}
	
	var userId = getUserId();
	 $.ajax({
        type : "put",
		url : window.baseUrl + "/api/book/borrowReturnLog/back",
		data : JSON.stringify({
			ids : ids,
			returnUid : userId,
			returnPid : bid,
			state : 2
		}),
		contentType : "application/json",
		success : function(data) {
			window.location.href = "readSuccess.html?successid=2";		
		}
	});
}
  
  
</script>
</html>